﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using System.Reflection;
using Castle.Core.Interceptor;

namespace JackyCode.Mock.Test
{
    [TestFixture]
    class TestMockObjectFactoryImpl
    {
        private class MockInterceptorStub : IMockInterceptor
        {
            public IList<int> Result { get; set; }

            public IMockData MockData { get; set; }

            public MockInterceptorStub()
            {
                Result = new List<int>();
            }

            public void Intercept(IInvocation invocation)
            {
                invocation.ReturnValue = "Hello";
                Result.Add(1);
            }
        }

        private MockInterceptorStub interceptor;
        private IMockObjectFactory<IService> iMockFactory;
        private IMockObjectFactory<Service> cMockFactory;

        [SetUp]
        public void Initialize()
        {
            interceptor = new MockInterceptorStub();
            iMockFactory = new MockObjectFactoryImpl<IService>(interceptor);
            cMockFactory = new MockObjectFactoryImpl<Service>(interceptor);
        }


        [Test]
        public void TestCreateObjectType()
        {
            Assert.IsTrue(iMockFactory.CreateObject() is IService);
            Assert.IsTrue(cMockFactory.CreateObject() is Service);
        }

        [Test]
        public void TestMethodCall()
        {
            Assert.AreEqual("Hello", iMockFactory.CreateObject().IReturnStrMethod());
            Assert.AreEqual(1, interceptor.Result.Count);
        }

    }
}
